<template>
  <BasicModal
    width="50%"
    :min-height="500"
    :show-ok-btn="false"
    v-bind="$attrs"
    @register="registerModal"
    title="查看"
  >
    <div class="h-200 flex-1">
      <Designer v-if="processXml" :xml="processXml" :isColored="true" :readOnly="true" />
    </div>
  </BasicModal>
</template>

<script lang="ts" setup name="bpmnView">
  import { ref } from 'vue';

  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { Designer } from '/@/components/BpmnChart';

  import { getTemplateDataApi } from '/@/api/config-center/bpmn-process';

  const processXml = ref('');
  const [registerModal, { changeLoading }] = useModalInner(async (data) => {
    try {
      changeLoading(true);

      await init(data);
    } catch (e) {
      throw e;
    } finally {
      changeLoading(false);
    }
  });

  async function init(data) {
    processXml.value = '';
    const { bpmnXml } = await getTemplateDataApi(data);

    processXml.value = bpmnXml;
  }
</script>
<style lang="less" scoped></style>
